#include <iostream>
#include <map>

#include "include/CardSet.h"
#include "include/combination.h"
#include "include/combinations.h"
#include "include/cardtools.h"
#include "include/cardtypes.h"

using namespace std;
using namespace stdcomb;

CCombination CombinationCalc;

map<unsigned int, unsigned int> Nothing;

map<unsigned int, CHand*> StrengthHandMap;

void display(vector<CCard>::iterator begin, vector<CCard>::iterator)
{
    CHand hand(begin);
    COMBINATION_TYPE comb = CombinationCalc.calcCombinationType( hand );
    if ( comb == ccStraightFlush )
    {
        unsigned int str = getCombinationStrength(comb, hand);
        Nothing[str]++;

        CHand* pHand = new CHand(begin);
        pHand->sortCards(CCardSet::stValue);
        StrengthHandMap[str] = pHand;
    }
}

class CBestCombinationFinder7
{
public:
    CBestCombinationFinder7() {}
    CHand findBestHand(CCardSet& cardSet);
private:
    int mSuit[4];
    int mVals[CCard::vAce];

};

CHand CBestCombinationFinder7::findBestHand(CCardSet& cardSet)
{
    bool isFlushPossible;
    bool isStraightPossible;
    bool isFourOfAKindPossible;
    bool isThreeOfAKindPossible;
    bool isPairPossible;


    for (int i = 0; i < 4; i++) mSuit[i] = 0;
    for (int i = 0; i < 13; i++) mVals[i] = 0;

    for (const CCard& card: cardSet)
    {
        mSuit[card.getSuit()]++;
        mVals[card.getValue()]++;
    }

    cardSet.sortCards(CCardSet::stValue);
}

int main()
{
    try
    {
        CCardSet pocket(2);
        pocket.addCard(CCard("KS"));
        pocket.addCard(CCard("AS"));

        CCardSet table(3);
        table.addCard(CCard("QS"));
        table.addCard(CCard("JS"));
        table.addCard(CCard("9D"));
        table.addCard(CCard("KD"));

        CHoldemCombinationsFinder holdemCalc;
        holdemCalc.findAllHands(pocket, table);

        cout << "Win: " << holdemCalc.mWin << endl;
        cout << "Draw: " << holdemCalc.mDraw << endl;
        cout << "Lose: " << holdemCalc.mLose << endl;

        cout  << endl << "Total: " << holdemCalc.mWin + holdemCalc.mDraw + holdemCalc.mLose;

//        for (size_t i = 0; i < 7462; i++)
//            if ( holdemCalc.mMyHandsCount[i] > 0 )
//            {
//                if ( ! holdemCalc.mMyHands[i] ) throw ( "CHand* is NULL" );
//                cout << i << " : "
//                     << CombinationTypeToString( holdemCalc.mMyHands[i]->getCombination() ) << "  "
//                     << holdemCalc.mMyHands[i]->getSignature() << "    = "
//                     << holdemCalc.mMyHandsCount[i] << endl;
//            }
    }
    catch (string& ex)
    {
        cout << "Exception: " << endl << ex;
    }
    catch (...)
    {
        cout << "Exception" << endl;
    }
    return 0;
}
